home *** CD-ROM | disk | FTP | other *** search
/ Stone Design / Stone Design.iso / Stone_Friends / Wave / WavesWorld / Source / Libraries / tcl7.4b3 / doc / switch.n < prev    next >
Encoding:
Text File  |  1994-12-17  |  3.5 KB  |  110 lines

  1. '\"
  2. '\" Copyright (c) 1993 The Regents of the University of California.
  3. '\" Copyright (c) 1994 Sun Microsystems, Inc.
  4. '\"
  5. '\" See the file "license.terms" for information on usage and redistribution
  6. '\" of this file, and for a DISCLAIMER OF ALL WARRANTIES.
  7. '\" 
  8. '\" @(#) switch.n 1.3 94/12/17 16:18:55
  9. '\" 
  10. .so man.macros
  11. .HS switch tcl 7.0
  12. .BS
  13. '\" Note:  do not modify the .SH NAME line immediately below!
  14. .SH NAME
  15. switch \- Evaluate one of several scripts, depending on a given value
  16. .SH SYNOPSIS
  17. \fBswitch\fI \fR?\fIoptions\fR?\fI string \fIpattern body \fR?\fIpattern body \fR...?
  18. .br
  19. \fBswitch\fI \fR?\fIoptions\fR?\fI string \fR{\fIpattern body \fR?\fIpattern body \fR...?}
  20. .BE
  21.  
  22. .SH DESCRIPTION
  23. .PP
  24. The \fBswitch\fR command matches its \fIstring\fR argument against each of
  25. the \fIpattern\fR arguments in order.
  26. As soon as it finds a \fIpattern\fR that matches \fIstring\fR it
  27. evaluates the following \fIbody\fR argument by passing it recursively
  28. to the Tcl interpreter and returns the result of that evaluation.
  29. If the last \fIpattern\fR argument is \fBdefault\fR then it matches
  30. anything.
  31. If no \fIpattern\fR argument
  32. matches \fIstring\fR and no default is given, then the \fBswitch\fR
  33. command returns an empty string.
  34. .PP
  35. If the initial arguments to \fBswitch\fR start with \fB\-\fR then
  36. they are treated as options.  The following options are
  37. currently supported:
  38. .TP 10
  39. \fB\-exact\fR
  40. Use exact matching when comparing \fIstring\fR to a pattern.  This
  41. is the default.
  42. .TP 10
  43. \fB\-glob\fR
  44. When matching \fIstring\fR to the patterns, use glob-style matching
  45. (i.e. the same as implemented by the \fBstring match\fR command).
  46. .TP 10
  47. \fB\-regexp\fR
  48. When matching \fIstring\fR to the patterns, use regular
  49. expression matching
  50. (i.e. the same as implemented by the \fBregexp\fR command).
  51. .TP 10
  52. \fB\-\|\-\fR
  53. Marks the end of options.  The argument following this one will
  54. be treated as \fIstring\fR even if it starts with a \fB\-.
  55. .PP
  56. Two syntaxes are provided for the \fIpattern\fR and \fIbody\fR arguments.
  57. The first uses a separate argument for each of the patterns and commands;
  58. this form is convenient if substitutions are desired on some of the
  59. patterns or commands.
  60. The second form places all of the patterns and commands together into
  61. a single argument; the argument must have proper list structure, with
  62. the elements of the list being the patterns and commands.
  63. The second form makes it easy to construct multi-line switch commands,
  64. since the braces around the whole list make it unnecessary to include a
  65. backslash at the end of each line.
  66. Since the \fIpattern\fR arguments are in braces in the second form,
  67. no command or variable substitutions are performed on them;  this makes
  68. the behavior of the second form different than the first form in some
  69. cases.
  70. .PP
  71. If a \fIbody\fR is specified as ``\fB\-\fR'' it means that the \fIbody\fR
  72. for the next pattern should also be used as the body for this
  73. pattern (if the next pattern also has a body of ``\fB\-\fR''
  74. then the body after that is used, and so on).
  75. This feature makes it possible to share a single \fIbody\fR among
  76. several patterns.
  77. .PP
  78. Below are some examples of \fBswitch\fR commands:
  79. .DS
  80. \fBswitch\0abc\0a\0\-\0b\0{format 1}\0abc\0{format 2}\0default\0{format 3}
  81. .DE
  82. will return \fB2\fR, 
  83. .DS
  84. .ta .5c 1c
  85. \fBswitch\0\-regexp\0aaab {
  86.     ^a.*b$\0\-
  87.     b\0{format 1}
  88.     a*\0{format 2}
  89.     default\0{format 3}
  90. }
  91. .DE
  92. will return \fB1\fR, and
  93. .DS
  94. .ta .5c 1c
  95. \fBswitch\0xyz {
  96.     a
  97.         \-
  98.     b
  99.         {format 1}
  100.     a*
  101.         {format 2}
  102.     default
  103.         {format 3}
  104. }
  105. .DE
  106. will return \fB3\fR.
  107.  
  108. .SH KEYWORDS
  109. switch, match, regular expression
  110.